﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BotonJXC.Entity;
using BotonJXC.Util;
using NHibernate;
using NHibernate.Criterion;

namespace BotonJXC.DAO
{
    public class PriceMaintenanceDAO : NHibernateDao<PriceInfo, int>
    {
     public void savePriceMaintenanc(PriceInfo priceInfoPros)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {

               base.Save(priceInfoPros);
                trans.Commit();
            }
            catch (HibernateException ex)
            {
                trans.Rollback();
                throw;

            }
            finally
            {
                HBHelper.Close();
            }

        }

     public void updatePriceMaintenanc(PriceInfo PriceInfo)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {

                base.Update(PriceInfo);
                trans.Commit();
            }
            catch (HibernateException ex)
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                HBHelper.Close();
            }

        }
     public void delPriceMaintenanc(PriceInfo PriceInfo)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {
              //  base.Delete(pip.PriceInfo.PriceInfoId);
                base.Delete(PriceInfo);
                trans.Commit();
            }
            catch (HibernateException ex)
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                HBHelper.Close();
            }
        }

     public PageModel<PriceInfo> FindPage(string PriceInfoSn, string CreaterName, string CreateTimeOne, string CreateTimeTwo, string Status, int start, int count)
     {
             List<ICriterion> criterions = new List<ICriterion>();
             if (Utils.IsNotBlank(PriceInfoSn))
             {
                 criterions.Add(Restrictions.Eq("PriceInfoSn", PriceInfoSn));
             }
             if (Utils.IsNotBlank(CreaterName))
             {  //new PriceInfo().Account.Username
                 criterions.Add(Restrictions.Like("Account.Username", CreaterName, MatchMode.Anywhere));
             }
             if (Utils.IsNotBlank(CreateTimeOne) || Utils.IsNotBlank(CreateTimeTwo))
             {
                 criterions.Add(Restrictions.Between("CreateTime", CreateTimeOne, CreateTimeTwo));
             }
             if (Utils.IsNotBlank(Status))
             {
                 criterions.Add(Restrictions.Eq("Status", Status));
             }
             Order order = new Order("CreateTime", true);

             return base.FindByPage(criterions.ToArray(), order, start, count);
         }
    }
}
